import { Rule } from "antd/lib/form";

export const camKeyName = "@#$%(^&%^CamKey";

export const deleteServeKeys = [
    "Type", "ServiceKey", "DataServerHeartTimer", "PictureServerHeartTimer",
    "NameServerHeartTimer", "FillLightStatus", "FillLightDelayTime",
    "FillLightOffTime", "FillLightOnTime", "BlackName", "WhiteName",
    "CheckIn", "FreeTime", "CameraCheckCarNo", "ETCCheckCarNo",
    "InDelayTime", "OutDelayTime", "NoCatchTime", "CarQuantity",
    "PictureQuantity", "EnterSensorIo", "ExistSensor",
    "LeaveSensor", "Lifer",
    // "VideoRecognition"
];

export const serveKeysMap2Val: {
    [key: string]: {
        name: string,
        rules?: Rule[],
        type?: {
            typeName: "inputNumber",
            min?: number,
            max?: number,
        }
    }
} = {
    "ParkId": {
        name: "停车场编号",
        rules: [
            {
                message: "只能输入纯数字",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            max: 10e20,
            min: 1
        },
    },
    "LogicId": {
        name: "逻辑id",
        rules: [
            {
                pattern: /^([0-9a-fA-F]{2}\s?)+$/,
                message: "只能十六进制",
                required: true
            },
        ]
    },
    "NetName": {
        name: "网卡名",
        rules: [
            {
                pattern: /^\w+$/,
                message: "只能数字或者字母",
                required: true
            },
        ]
    },
    "Ip": {
        name: "Ip",
        rules: [
            {
                pattern: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
                message: "只能是ipv4地址",
                required: true
            },
        ]
    },
    "Netmask": {
        name: "子网掩码",
        rules: [
            {
                pattern: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
                message: "只能是ipv4地址",
                required: true
            },
        ]
    },
    "Gateway": {
        name: "网关",
        rules: [
            {
                pattern: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
                message: "只能是ipv4地址",
                required: true
            },
        ]
    },
    "QxUser": {
        name: "千寻用户名",
        rules: [
            {
                message: "需要输入用户名",
                required: true
            },
        ]
    },
    "QxPassword": {
        name: "千寻密码",
        rules: [
            {
                message: "需要输入密码",
                required: true
            },
        ],

    },
    "QxServiceName": {
        name: "千寻域名",
        rules: [
            {
                message: "需要输入域名",
                required: true
                // TODO: 域名的正则校验
            },
        ],

    },
    "QxPort": {
        name: "千寻端口",
        rules: [
            {
                message: "需要输入数字",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            max: 65532,
            min: 1024
        },
    },
    "QxReportInterval": {
        name: "千寻上报时间间隔(s)",
        rules: [
            {
                message: "需要输入数字",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            max: 600,
            min: 1
        },
    },
    "UploadSpeed": {
        name: "静止速度(m/s)",
        rules: [
            {
                message: "需要输入数字",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            max: 600,
            min: 0.000001
        },
    },
    "UploadKeepTime": {
        name: "静止速度保持时间(s)",
        rules: [
            {
                message: "需要输入数字",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            max: 600,
            min: 0
        },
    },
    "UploadPicMaxNumber": {
        name: "图片缓存最大数量",
        rules: [
            {
                message: "需要输入数字",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            max: 50000,
            min: 1
        },
    },
    "CalibrationDelta": {
        name: "标定差",
        rules: [
            {
                message: "需要输入数字",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            min: 0.0000001
        },
    },
    "WifiSsid": {
        name: "wifi名",
        rules: [
            {
                message: "输入wifi名称",
                required: true
            },
        ],
    },
    "WifiPwd": {
        name: "wifi密码",
        rules: [
            {
                message: "输入wifi密码",
                required: true
            },
        ],
    },
};

export const deleteCamsKeys = [
    "Vendor", "Producter"
];

export const getCamsKeysMap2Val = (index: number): {
    [key: string]: {
        name: string,
        rules?: Rule[],
        type?: {
            typeName: "inputNumber",
            min?: number,
            max?: number,
        }
    }
} => ({
    [`Id${camKeyName}${index}`]: {
        name: "相机id",
        rules: [
            {
                message: "只能输入纯数字",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            max: 255,
            min: 0
        },
    },
    [`Remark${camKeyName}${index}`]: {
        name: "相机备注",
        rules: [
            {
                message: "备注不能为空",
                required: true
            },
        ]
    },
    [`Ip${camKeyName}${index}`]: {
        name: "Ip",
        rules: [
            {
                pattern: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
                message: "只能是ipv4地址",
                required: true
            },
        ]
    },
    [`Port${camKeyName}${index}`]: {
        name: "端口",
        rules: [
            {
                message: "输入端口",
                required: true
            },
        ],
        type: {
            typeName: "inputNumber",
            max: 65532,
            min: 1024
        },
    },
});

export function guid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0,
            v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}

export const getRequestUrl = () => "http://localhost"